home *** CD-ROM | disk | FTP | other *** search
/ X User Tools / X User Tools (O'Reilly and Associates)(1994).ISO / sources / xman / main.c < prev    next >
C/C++ Source or Header  |  1994-09-27  |  9KB  |  244 lines

  1. /*
  2.  * xman - X window system manual page display program.
  3.  *
  4.  * $XConsortium: main.c,v 1.21 91/09/03 18:16:55 dave Exp $
  5.  *
  6.  * Copyright 1987, 1988 Massachusetts Institute of Technology
  7.  *
  8.  * Permission to use, copy, modify, and distribute this software and its
  9.  * documentation for any purpose and without fee is hereby granted, provided
  10.  * that the above copyright notice appear in all copies and that both that
  11.  * copyright notice and this permission notice appear in supporting
  12.  * documentation, and that the name of M.I.T. not be used in advertising or
  13.  * publicity pertaining to distribution of the software without specific,
  14.  * written prior permission.  M.I.T. makes no representations about the
  15.  * suitability of this software for any purpose.  It is provided "as is"
  16.  * without express or implied warranty.
  17.  *
  18.  * Author:    Chris D. Peterson, MIT Project Athena
  19.  * Created:   October 22, 1987
  20.  */
  21.  
  22. #include "globals.h"
  23. #ifndef ZERO
  24. #include <X11/Xaw/Cardinals.h>
  25. #endif /* ZERO */
  26.  
  27. #if ( !defined(lint) && !defined(SABER)) /* Version can be retrieved */
  28.   static char version[] = XMAN_VERSION;  /* via strings. */
  29. #endif
  30.  
  31. static void ArgError();
  32.  
  33. #define Offset(field) (XtOffsetOf(Xman_Resources , field))
  34.  
  35. static XtResource my_resources[] = {
  36.   {"directoryFontNormal", XtCFont, XtRFontStruct, sizeof(XFontStruct *),
  37.      Offset(fonts.directory), XtRString, DIRECTORY_NORMAL},
  38.   {"bothShown", XtCBoolean, XtRBoolean, sizeof(Boolean),
  39.      Offset(both_shown_initial), XtRString, "False"},
  40.   {"directoryHeight", "DirectoryHeight", XtRInt, sizeof(int),
  41.      Offset(directory_height), XtRString, "150"},  
  42.   {"topCursor", XtCCursor, XtRCursor, sizeof(Cursor), 
  43.      Offset(cursors.top), XtRString, XMAN_CURSOR},
  44.   {"helpCursor", XtCCursor, XtRCursor, sizeof(Cursor),
  45.      Offset(cursors.help), XtRString, HELP_CURSOR},
  46.   {"manpageCursor", XtCCursor, XtRCursor, sizeof(Cursor),
  47.      Offset(cursors.manpage), XtRString, MANPAGE_CURSOR},
  48.   {"searchEntryCursor", XtCCursor, XtRCursor, sizeof(Cursor),
  49.      Offset(cursors.search_entry), XtRString, SEARCH_ENTRY_CURSOR},
  50.   {"pointerColor", XtCForeground, XtRPixel, sizeof(Pixel),
  51.      Offset(cursors.fg_color), XtRString, "XtDefaultForeground"},
  52.   {"pointerColorBackground", XtCBackground, XtRPixel, sizeof(Pixel),
  53.      Offset(cursors.bg_color), XtRString, "XtDefaultBackground"},
  54.   {"help", XtCBoolean, XtRBoolean, sizeof(Boolean),
  55.      Offset(show_help_syntax), XtRImmediate, FALSE},
  56.   {"helpFile", XtCFile, XtRString, sizeof(char *),
  57.      Offset(help_file), XtRString, HELPFILE},
  58.   {"topBox", XtCBoolean, XtRBoolean, sizeof(Boolean),
  59.      Offset(top_box_active), XtRString, "True"},
  60.   {"clearSearchString", "ClearSearchString", XtRBoolean, sizeof(Boolean),
  61.      Offset(clear_search_string), XtRImmediate, (caddr_t) TRUE},
  62.   {"title", XtCString, XtRString, sizeof(char *),
  63.      Offset(title), XtRString, "xman"},
  64.   {"iconic", XtCBoolean, XtRBoolean, sizeof(Boolean),
  65.      Offset(iconic), XtRString, "False"},
  66. };
  67.  
  68. #undef Offset
  69.  
  70. /*
  71.  * The resource that we absolutely need.
  72.  */
  73.  
  74. static char * fallback_resources[] = { "Xman*quitButton.translations:    #override \\n   <Btn1Up>: Quit() reset()",
  75.  "Xman*helpButton.sensitive:                    FALSE",
  76.  "Xman*manpageButton.sensitive:                 FALSE",
  77.  "Xman*helpButton.Label:            Help",
  78.  "Xman*quitButton.Label:            Quit",
  79.  "Xman*manpageButton.Label:                Manual Page",
  80.  "Xman*topLabel.label:                         No App-Defaults File",
  81.  NULL,
  82. };
  83.  
  84. /*
  85.  * This is necessary to keep all TopLevel shells from becoming
  86.  * the size that is specified on the command line.
  87.  */
  88.  
  89. static XrmOptionDescRec xman_options[] = {
  90. {"-geometry", "*topBox.geometry",        XrmoptionSepArg, (caddr_t) NULL},
  91. {"-help",     "help",                    XrmoptionNoArg,  (caddr_t) "True"},
  92. {"=",         "*topBox.geometry",        XrmoptionIsArg,  (caddr_t) NULL},
  93. {"-pagesize", "*manualBrowser.geometry", XrmoptionSepArg, (caddr_t) NULL},
  94. {"-notopbox", "topBox",                  XrmoptionNoArg,  (caddr_t) "False"},
  95. {"-helpfile", "helpFile",                XrmoptionSepArg, (caddr_t) NULL},
  96. {"-bothshown","bothShown",               XrmoptionNoArg,  (caddr_t) "True"},
  97. {"-title",    "title",                   XrmoptionSepArg, (caddr_t) "xman"}, 
  98. {"-iconic",   "iconic",                  XrmoptionNoArg,  (caddr_t) "True"},
  99. };
  100.  
  101. XtActionsRec xman_actions[] = {
  102.   {"GotoPage",          GotoPage},
  103.   {"Quit",              Quit},
  104.   {"Search",            Search},
  105.   {"PopupHelp",         PopupHelp},
  106.   {"PopupSearch",       PopupSearch},
  107.   {"CreateNewManpage",  CreateNewManpage},
  108.   {"RemoveThisManpage", RemoveThisManpage},
  109.   {"SaveFormattedPage", SaveFormattedPage},
  110.   {"ShowVersion",       ShowVersion},
  111. };
  112.  
  113. char **saved_argv;
  114. int saved_argc;
  115.  
  116.  
  117. /*    Function Name: main
  118.  *    Description: This is the main driver for Xman.
  119.  *    Arguments: argc, argv - the command line arguments.
  120.  *    Returns: return, what return.
  121.  */
  122.  
  123. void 
  124. main(argc,argv)
  125. char ** argv;
  126. int argc;
  127. {
  128.   XtAppContext app_con;
  129.  
  130.   saved_argc = argc;
  131.   saved_argv = (char **)XtMalloc(argc * sizeof(char *));
  132.   bcopy(argv, saved_argv, argc * sizeof(char *));
  133.  
  134.   initial_widget = XtAppInitialize(&app_con, "Xman", xman_options,
  135.                    XtNumber(xman_options), &argc, argv,
  136.                    fallback_resources, NULL, ZERO);
  137.  
  138.   manglobals_context = XStringToContext(MANNAME);
  139.  
  140.   XtGetApplicationResources( initial_widget, (caddr_t) &resources, 
  141.                 my_resources, XtNumber(my_resources),
  142.                 NULL, (Cardinal) 0);
  143.  
  144.   if ( (argc != 1) || (resources.show_help_syntax) ) {
  145.     ArgError(argc, argv);
  146.     exit(1);
  147.   }
  148.  
  149.   XtAppAddActions(app_con, xman_actions, XtNumber(xman_actions));
  150.  
  151.   if (!resources.fonts.directory)
  152.     PrintError("Failed to get the directory font.");
  153.  
  154. #ifdef DEBUG
  155.   printf("debugging mode\n");
  156. #endif
  157.  
  158. /*
  159.  * Set the default width and height.
  160.  * I am not real happy with this method, but it will usually do something
  161.  * reasonable, if not the "right" thing.  It is not a real big issue since
  162.  * it is easy to change the values with resources or command line options.
  163.  * NOTE: if you are in a 100 dpi display you will lose.
  164.  */
  165.  
  166.   default_width = DEFAULT_WIDTH;
  167.   default_height=DisplayHeight(XtDisplay(initial_widget), 
  168.                    XtDisplay(initial_widget)->default_screen);
  169.   default_height *= 3;
  170.   default_height /= 4;
  171.  
  172.   if ( (sections = Man()) == 0 )
  173.     PrintError("There are no manual sections to display, check your MANPATH.");
  174.  
  175.   if (resources.top_box_active) 
  176.     MakeTopBox();    
  177.   else
  178.     (void) CreateManpage(NULL);
  179.  
  180. /*
  181.  * We need to keep track of the number of manual pages that are shown on
  182.  * the screen so that if this user does not have a top box then when he
  183.  * removes all his manual pages we can kill off the xman process.
  184.  * To make things easier we will consider the top box a shown manual page
  185.  * here, but since you cannot remove it, man_page_shown only goes to zero when
  186.  * no top box is present.
  187.  */
  188.  
  189.   man_pages_shown = 1;        
  190.  
  191.   XtAppMainLoop(app_con);
  192. }
  193.  
  194. /*    Function Name: ArgError
  195.  *    Description:  Prints error message about unknow arguments.
  196.  *    Arguments: argc, argv - args not understood.
  197.  *    Returns: none.
  198.  */
  199.  
  200. static void 
  201. ArgError(argc, argv)
  202. char ** argv;
  203. int argc;
  204. {
  205.   int i;
  206.  
  207.   static char **syntax, *syntax_def[] = {
  208.   "-help",                   "Print this message",
  209.   "-helpfile <filename>",    "Specifies the helpfile to use.",
  210.   "-bothshown",              "Show both the directory and manpage at once.",
  211.   "-notopbox",               "Starts with manpage rather than topbox.",
  212.   "-geometery <geom>",       "Specifies the geometry of the top box.",
  213.   "=<geom>",                 "Specifies the geometry of the top box.",
  214.   "-pagesize <geom>",        "Specifies the geometry of the manual page.",
  215.   "-bw <pixels>",            "Width of all window borders.",
  216.   "-borderwidth <pixels>",   "Width of all window borders.",
  217.   "-bd <color>",             "Color of all window borders.",
  218.   "-bordercolor <color>",    "Color of all window borders.",
  219.   "-fg <color>",             "Foreground color for the application.",
  220.   "-foreground <color>",     "Foreground color for the application.",
  221.   "-bg <color>",             "Background color for the application.",
  222.   "-background <color>",     "Background color for the application.",
  223.   "-display <display name>", "Specify a display that is not the default",
  224.   "-fn <font>",              "Font to be used for button and label text.",
  225.   "-font <font>",            "Font to be used for button and label text.",
  226.   "-name <name>",            "Change the name used for retrieving resources.",
  227.   "-title <name>",           "Change the name without affecting resources.",
  228.   "-xrm <resource>",         "Specifies a resource on the command line.",
  229.   NULL, NULL,
  230.   };
  231.   
  232.   syntax = syntax_def;
  233.  
  234.   for (i = 1; i < argc ; i++) 
  235.     (void) printf("This argument is unknown to Xman: %s\n", argv[i]);
  236.   
  237.   (void) printf("\nKnown arguments are:\n");
  238.  
  239.   while ( *syntax != NULL ) {
  240.     printf("%-30s - %s\n", syntax[0], syntax[1]);
  241.     syntax += 2;
  242.   }
  243. }
  244.